package com.hottop.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hottop.common.annotation.Log;
import com.hottop.common.core.controller.BaseController;
import com.hottop.common.core.domain.AjaxResult;
import com.hottop.common.enums.BusinessType;
import com.hottop.system.domain.SysAnnouncement;
import com.hottop.system.service.ISysAnnouncementService;
import com.hottop.common.utils.poi.ExcelUtil;
import com.hottop.common.core.page.TableDataInfo;

/**
 * 系统公告数据Controller
 * 
 * @author ruoyi
 * @date 2022-02-19
 */
@RestController
@RequestMapping("/system/announcement")
public class SysAnnouncementController extends BaseController
{
    @Autowired
    private ISysAnnouncementService sysAnnouncementService;

    /**
     * 查询系统公告数据列表
     */
    @PreAuthorize("@ss.hasPermi('system:announcement:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysAnnouncement sysAnnouncement)
    {
        startPage();
        List<SysAnnouncement> list = sysAnnouncementService.selectSysAnnouncementList(sysAnnouncement);
        return getDataTable(list);
    }

    /**
     * 导出系统公告数据列表
     */
    @PreAuthorize("@ss.hasPermi('system:announcement:export')")
    @Log(title = "系统公告数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAnnouncement sysAnnouncement)
    {
        List<SysAnnouncement> list = sysAnnouncementService.selectSysAnnouncementList(sysAnnouncement);
        ExcelUtil<SysAnnouncement> util = new ExcelUtil<SysAnnouncement>(SysAnnouncement.class);
        util.exportExcel(response, list, "系统公告数据数据");
    }

    /**
     * 获取系统公告数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:announcement:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sysAnnouncementService.selectSysAnnouncementById(id));
    }

    /**
     * 新增系统公告数据
     */
    @PreAuthorize("@ss.hasPermi('system:announcement:add')")
    @Log(title = "系统公告数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAnnouncement sysAnnouncement)
    {
        return toAjax(sysAnnouncementService.insertSysAnnouncement(sysAnnouncement));
    }

    /**
     * 修改系统公告数据
     */
    @PreAuthorize("@ss.hasPermi('system:announcement:edit')")
    @Log(title = "系统公告数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAnnouncement sysAnnouncement)
    {
        return toAjax(sysAnnouncementService.updateSysAnnouncement(sysAnnouncement));
    }

    /**
     * 删除系统公告数据
     */
    @PreAuthorize("@ss.hasPermi('system:announcement:remove')")
    @Log(title = "系统公告数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysAnnouncementService.deleteSysAnnouncementByIds(ids));
    }
}
